package com.fenghongzhang.day009viewgroup;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class MainActivity extends AppCompatActivity {
    private MyView myview;

    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myview = (MyView) findViewById(R.id.myview);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        switch (event.getAction()){

            case MotionEvent.ACTION_DOWN:
                float x = event.getX();
                float y = event.getY();
                Log.i(TAG, "onTouchEvent: "+x);
                Log.i(TAG, "onTouchEvent: "+y);
                break;

            case MotionEvent.ACTION_MOVE:
                myview.setTranslationX(event.getX());
                myview.setTranslationY(event.getY()-200);
                break;

            case MotionEvent.ACTION_UP:

                break;
        }


        return super.onTouchEvent(event);
    }
}
